package com.szpx.service.impl;

import com.szpx.entity.Consumer;
import com.szpx.mapper.ConsumerMapper;
import com.szpx.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsumerServiceImpl implements ConsumerService {
    @Autowired
    private ConsumerMapper consumerMapper;



    @Override
    public boolean register(Consumer consumer) {
        // 检查密码是否匹配
        if (!consumer.getPassword().equals(consumer.getConfirmPassword())) {
            return false;
        }

        // 检查用户名和邮箱是否已存在
        Consumer existingConsumer = consumerMapper.selectByUsername(consumer.getUsername());
        if (existingConsumer != null) {
            return false; // 用户名已存在
        }

        existingConsumer = consumerMapper.selectByEmail(consumer.getEmail());
        if (existingConsumer != null) {
            return false; // 邮箱已存在
        }

        // 如果验证通过，将用户信息保存到数据库
        consumerMapper.insertConsumer(consumer);
        return true; // 注册成功
    }

    @Override
    public List<Consumer> selectAllUser() {
        return null;
    }

    @Override
    public boolean login(String login) {
        return false;
    }
}